/**
 * 获取画布中唯一的节点ID
 * @param { HTMLElement }  elementGraph -- antv x6 元素
 */
const getNodeMaxId = (elementGraph: any) => {
  const nodeList = elementGraph.getNodes();
  const ids: number[] = [];
  nodeList.forEach((item: any) => {
    if (item.id.startsWith("n")) {
      const nodeId: number = parseInt(item.id.replace("n", ""));
      ids.push(nodeId);
    }
  });
  const nodeIdOnly = ids.length ? Math.max(...ids) : 0;
  return nodeIdOnly + 1;
};

/**
 * 获取画布中唯一的边ID
 * @param { HTMLElement }  elementGraph -- antv x6 元素
 */
const getEdgeMaxId = (elementGraph: any) => {
  const edgeList = elementGraph.getEdges();
  const ids: number[] = [];
  edgeList.forEach((item: any) => {
    if (item.id.startsWith("e")) {
      const edgeId: number = parseInt(item.id.replace("e", ""));
      ids.push(edgeId);
    }
  });
  const edgeIdOnly = ids.length ? Math.max(...ids) : 0;
  return edgeIdOnly + 1;
};

export { getNodeMaxId, getEdgeMaxId };
